package rs.pnv.model.card;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotBlank;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_CARD_INFORMATION")
@XmlAccessorType(XmlAccessType.FIELD)
public class CardInformation extends AbstractEntity {

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String pan; // FIXME da li je string?

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String securityCode; // FIXME da li je string?

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String cardHolderName;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private Date expirationDate;

	public CardInformation() {

	}

	public String getPan() {
		return pan;
	}

	public void setPan(String pan) {
		this.pan = pan;
	}

	public String getSecurityCode() {
		return securityCode;
	}

	public void setSecurityCode(String securityCode) {
		this.securityCode = securityCode;
	}

	public String getCardHolderName() {
		return cardHolderName;
	}

	public void setCardHolderName(String cardHolderName) {
		this.cardHolderName = cardHolderName;
	}

	public Date getExpirationDate() {
		return expirationDate;
	}

	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(pan)
				.append(securityCode)
				.append(cardHolderName)
				.append(expirationDate)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final CardInformation otherCard = (CardInformation) obj;

		return new EqualsBuilder()
				.append(pan, otherCard.getPan())
				.append(securityCode, otherCard.getSecurityCode())
				.append(cardHolderName, otherCard.getCardHolderName())
				.append(expirationDate, otherCard.getExpirationDate())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("pan", pan)
				.append("securityCode", securityCode)
				.append("cardHolderName", cardHolderName)
				.append("expirationDate", expirationDate)
				.append(super.toString())
				.toString();
	}
}
